home *** CD-ROM | disk | FTP | other *** search
/ Ultimate Add-On's (Tournament Edition) / Cybercore Publishing - Ultimate Add-on's Tournament Edition.iso / d2 / disgnews.per < prev    next >
Text File  |  1995-01-26  |  8KB  |  308 lines

  1. # Install new sprites for DISGRUNT
  2.  
  3. &main();
  4.  
  5. sub main
  6. {
  7.     local($action);
  8.     local($dmgraph) =".\\dmgraph.exe";
  9.     local($doomdir);
  10.     local($new_sprites_dir);
  11.     local($ok);
  12.     local($old_sprites_dir);
  13.     local($stuff);
  14.  
  15.     print "Install or Uninstall DISGRUNT Graphics\n";
  16.  
  17.     unless ( -x $dmgraph )
  18.     {
  19.         &error("DMGRAPH is missing");
  20.     }
  21.  
  22.     for ( $ok = 0; !$ok; )
  23.     {
  24.         print "I)nstall, U)ninstall or Q)uit (I/U/Q)? ";
  25.         chop($stuff = <STDIN>);
  26.         ($stuff) =~ /^\s*(\S+)\s*$/;
  27.         if (length($stuff) > 0)
  28.         {
  29.             $stuff = substr($stuff, 0, 1);
  30.             $stuff =~ y/a-z/A-Z/;
  31.             if ( $stuff eq "I" || $stuff eq "U" || $stuff eq "Q" )
  32.             {
  33.                 $ok = 1;
  34.             }
  35.         }
  36.     }
  37.  
  38.     $action = $stuff;
  39.  
  40.     if ( $action eq "Q" )
  41.     {
  42.         print "Bye!";
  43.         exit;
  44.     }
  45.  
  46.     for ( $ok = 0; !$ok; )
  47.     {
  48.         print "Where is your DOOM directory? ";
  49.         chop($stuff = <STDIN>);
  50.         ($stuff) =~ /^\s*(\S+)\s*$/;
  51.         if (length($stuff) > 0)
  52.         {
  53.             $stuff =~ y/A-Z/a-z/;
  54.             $stuff =~ y/\//\\/;
  55.             unless ( -d $stuff )
  56.             {
  57.                 print "$stuff is not a directory\n";
  58.             }
  59.             else
  60.             {
  61.                 unless ( -e "$stuff\\doom.wad" && -x "$stuff\\doom.exe" )
  62.                 {
  63.                     print "DOOM.WAD and DOOM.EXE not found in $stuff\n";
  64.                 }
  65.                 else
  66.                 {
  67.                     $ok = 1;
  68.                 }
  69.             }
  70.         }
  71.     }
  72.  
  73.     $doomdir = $stuff;
  74.     $new_sprites_dir = "$doomdir\\disgnews";
  75.     $old_sprites_dir = "$doomdir\\disgolds";
  76.  
  77.     if ( $action eq "I" )
  78.     {
  79.         print "Install DISGRUNT graphics in $doomdir\n";
  80.         unless ( -d $new_sprites_dir )
  81.         {
  82.             &error("New sprites directory $new_sprites_dir is missing");
  83.         }
  84.  
  85.         &hit_return();
  86.         &install($doomdir, $new_sprites_dir, $dmgraph);
  87.     }
  88.     else
  89.     {
  90.         print "Uninstall DISGRUNT graphics in $doomdir\n";
  91.         &hit_return();
  92.         &uninstall($doomdir, $old_sprites_dir, $dmgraph);
  93.     }
  94. }    
  95.  
  96. sub install
  97. {
  98.     local($doomdir, $new_sprites_dir, $dmgraph) = @_;
  99.  
  100.     local($old_sprites_dir) = "$doomdir\\disgolds";
  101.     local($tmp_sprites_dir) = "$doomdir\\disgtmps";
  102.     local($sprite);
  103.     local($spritename);
  104.     local(@sprites_files);
  105.     local(@sprites);
  106.     local(%imp_sprites) = 
  107.         (
  108.          "trooa1", "sposa1",
  109.          "trooa2a8", "sposa2a8",
  110.          "trooa3a7", "sposa3a7",
  111.          "trooa4a6", "sposa4a6",
  112.          "trooa5", "sposa5",
  113.  
  114.          "troob1", "sposb1",
  115.          "troob2b8", "sposb2b8",
  116.          "troob3b7", "sposb3b7",
  117.          "troob4b6", "sposb4b6",
  118.          "troob5", "sposb5",
  119.  
  120.          "trooc1", "sposc1",
  121.          "trooc2c8", "sposc2c8",
  122.          "trooc3c7", "sposc3c7",
  123.          "trooc4c6", "sposc4c6",
  124.          "trooc5","sposc5",
  125.  
  126.          "trood1", "sposd1",
  127.          "trood2d8", "sposd2d8",
  128.          "trood3d7", "sposd3d7",
  129.          "trood4d6", "sposd4d6",
  130.          "trood5","sposd5",
  131.  
  132.          "trooe1", "spose1",
  133.          "trooe2e8", "spose2e8",
  134.          "trooe3e7", "spose3e7",
  135.          "trooe4e6", "spose4e6",
  136.          "trooe5","spose5",
  137.  
  138.          "troof1", "spose1",
  139.          "troof2f8", "spose2e8",
  140.          "troof3f7", "spose3e7",
  141.          "troof4f6", "spose4e6",
  142.          "troof5","spose5",
  143.  
  144.          "troog1", "sposf1",
  145.          "troog2g8", "sposf2f8",
  146.          "troog3g7", "sposf3f7",
  147.          "troog4g6", "sposf4f6",
  148.          "troog5","sposf5",
  149.  
  150.          "trooh1", "sposg1",
  151.          "trooh2h8", "sposg2g8",
  152.          "trooh3h7", "sposg3g7",
  153.          "trooh4h6", "sposg4g6",
  154.          "trooh5","sposg5",
  155.  
  156.          "trooi0", "sposm0",
  157.          "trooj0", "sposn0",
  158.          "trook0", "sposo0",
  159.          "trool0", "sposq0",
  160.          "troom0","sposu0",
  161.          "troon0", "sposm0",
  162.          "trooo0", "sposn0",
  163.          "troop0", "sposo0",
  164.          "trooq0", "sposp0",
  165.          "troor0", "sposq0",
  166.          "troos0", "sposr0",
  167.          "troot0", "sposs0",
  168.          "troou0", "sposu0"
  169.          );
  170.  
  171.     unless ( -d $old_sprites_dir )
  172.     {
  173.         system("mkdir $old_sprites_dir");
  174.         unless ( -d $old_sprites_dir )
  175.         {
  176.             &error("$old_sprites_dir does not exist, failed to create it");
  177.         }
  178.     }
  179.  
  180.     unless ( -d $tmp_sprites_dir )
  181.     {
  182.         system("mkdir $tmp_sprites_dir");
  183.         unless ( -d $tmp_sprites_dir )
  184.         {
  185.             &error("$tmp_sprites_dir does not exist, failed to create it");
  186.         }
  187.     }
  188.  
  189.     unless ( opendir(SPRITES, $new_sprites_dir) )
  190.     {
  191.         &error("Failed to open new sprites directory $new_sprites_dir " .
  192.                "for input");
  193.     }
  194.     @sprites_files = readdir(SPRITES);
  195.     closedir(SPRITES);
  196.  
  197.     @sprites_files = grep(/\w+\.GIF/i, @sprites_files);
  198.     @sprites = grep(s/\.GIF//i, @sprites_files);
  199.  
  200.     print "Backing up sprites that will be replaced...\n";
  201.  
  202.     foreach $sprite (@sprites)
  203.     {
  204.         &backup_sprite($sprite, $old_sprites_dir, $dmgraph);
  205.     }
  206.  
  207.     foreach $sprite (sort keys %imp_sprites)
  208.     {
  209.         &backup_sprite($sprite, $old_sprites_dir, $dmgraph);
  210.     }
  211.  
  212.     foreach $sprite (sort keys %imp_sprites)
  213.     {
  214.         &backup_sprite($imp_sprites{$sprite}, $tmp_sprites_dir, $dmgraph);
  215.     }
  216.  
  217.     print "Replacing sprites in DOOM.WAD...\n";
  218.     foreach $sprite (@sprites)
  219.     {
  220.         &install_sprite($sprite, $new_sprites_dir, $dmgraph);
  221.     }
  222.  
  223.     foreach $sprite (sort keys %imp_sprites)
  224.     {
  225.         $new_sprite_file = "$new_sprites_dir\\$imp_sprites{$sprite}.gif";
  226.         unless ( -e $new_sprite_file )
  227.         {
  228.             $new_sprite_file = "$tmp_sprites_dir\\$imp_sprites{$sprite}.gif";
  229.         }
  230.         print "Installing $sprite from $new_sprite_file...\n";
  231.         system("$dmgraph $sprite -s $new_sprite_file");
  232.     }
  233.  
  234.     print "Deleting temporary directory...";
  235.     system("echo y | del $tmp_sprites_dir\\*.* >nul");
  236.     system("rmdir $tmp_sprites_dir");
  237. }
  238.  
  239. sub uninstall
  240. {
  241.     local($doomdir, $old_sprites_dir, $dmgraph) = @_;
  242.  
  243.     local(@sprites_files);
  244.     local(@sprites);
  245.  
  246.     unless ( opendir(SPRITES, $old_sprites_dir) )
  247.     {
  248.         &error("Failed to open old sprites directory $old_sprites_dir " .
  249.                "for input");
  250.     }
  251.     @sprites_files = readdir(SPRITES);
  252.     closedir(SPRITES);
  253.  
  254.     @sprites_files = grep(/\w+\.GIF/i, @sprites_files);
  255.     @sprites = grep(s/\.GIF//i, @sprites_files);
  256.  
  257.     print "Restoring sprites backed up by the install procedure...\n";
  258.     foreach $sprite (@sprites)
  259.     {
  260.         &install_sprite($sprite, $old_sprites_dir, $dmgraph);
  261.     }
  262.     print "Your DOOM is good as new (what could go wrong?)\n";
  263. }
  264.  
  265. sub error
  266. {
  267.     local($msg) = @_;
  268.  
  269.     print "Error: $msg\n";
  270.     exit;
  271. }
  272.  
  273. sub backup_sprite
  274. {
  275.     local($sprite, $old_sprites_dir, $dmgraph) = @_;
  276.     local($old_sprite_file);
  277.  
  278.     $old_sprite_file = "$old_sprites_dir\\$sprite.gif";
  279.     if ( -e $old_sprite_file )
  280.     {
  281.         print "$sprite has already been extracted " . 
  282.             "to $old_sprite_file\n";
  283.     }
  284.     else
  285.     {
  286.         print "Extracting $sprite to $old_sprite_file...\n";
  287.         system("$dmgraph $sprite -e $old_sprite_file");
  288.     }
  289. }
  290.  
  291. sub install_sprite
  292. {
  293.     local($sprite, $new_sprites_dir, $dmgraph) = @_;
  294.     local($new_sprite_file);
  295.  
  296.     $new_sprite_file = "$new_sprites_dir\\$sprite.gif";
  297.     print "Installing $sprite from $new_sprite_file...\n";
  298.     system("$dmgraph $sprite -s $new_sprite_file");
  299. }
  300.  
  301. sub hit_return
  302. {
  303.     local($stuff);
  304.  
  305.     print "Hit RETURN to continue\n";
  306.     $stuff = <STDIN>;
  307. }
  308.